# -*- coding: utf-8 -*-
# author yzs
# date 2019-03-04
'''
按照要求保留数组元素使得和最大
Description
Given an array of N numbers, we need to maximize the sum of selected numbers.
At each step, you need to select a number Ai, delete one occurrence of Ai-1 (if exists) and Ai each from the array.
Repeat these steps until the array gets empty. The problem is to maximize the sum of selected numbers. 必须从大到小选择元素。
Input
The first line of the input contains T denoting the number of the test cases. For each test case,
the first line contains an integer n denoting the size of the array. Next line contains n space separated integers
denoting the elements of the array. 数组元素已经按照从小到大顺序排列。
Output
For each test case, the output is an integer displaying the maximum sum of selected numbers.
Sample Input 1 
1
3
1 2 3
Sample Output 1
4
'''


def select_nums(arr):
    sum = 0
    while len(arr) > 0:
        max = arr.pop()
        sum += max
        if arr and max-1 in arr:
            arr.remove(max-1)
    print(sum)


t = int(input().strip())
for _ in range(t):
    n = int(input().strip())
    datas = list(map(int, input().strip().split()))[:n]
    select_nums(datas)